package com.youlu.campus.admin.task;

import com.youlu.campus.wechat.service.impl.MerchantComplaintService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * 商户号投诉同事补偿Job
 */
@Slf4j
@Component
public class MerchantComplaintNotifyTask {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private MerchantComplaintService merchantComplaintService;

    /**
     * 每60分钟执行一次
     */
    //@Scheduled(cron = "0 0 0/1 * * ?")
    public void handleNotifyJob(){
        Boolean flag = redisTemplate.opsForValue().setIfAbsent("merchant:complaint:notify", "1", 3L, TimeUnit.MINUTES);
        if(Objects.nonNull(flag)&&!flag){
            return;
        }
        merchantComplaintService.handleNotifyJob();
    }
}
